﻿using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace HML.Design
{
    /// <summary>
    /// 水波纹控件设计模式行为
    /// </summary>
    public class WaterRipplesDesigner : ControlDesigner
    {
        protected override void OnPaintAdornments(PaintEventArgs pe)
        {
            base.OnPaintAdornments(pe);

            // 绘制虚线边框
            WaterRipples control = (WaterRipples)this.Control;
            if (control.BorderThickness == 0)
            {
                Pen pen = new Pen((double)control.BackColor.GetBrightness() >= 0.5 ? ControlPaint.Dark(control.BackColor) : ControlPaint.Light(control.BackColor)) { DashStyle = DashStyle.Dash };
                if (control.StylePattern == WaterRipplesStylePattern.Quadrangle)
                {
                    pe.Graphics.DrawRectangle(pen, new Rectangle(control.ClientRectangle.X, control.ClientRectangle.Y, control.ClientRectangle.Width - 1, control.ClientRectangle.Height - 1));
                }
                else
                {
                    pe.Graphics.DrawEllipse(pen, new Rectangle(control.ClientRectangle.X + 1, control.ClientRectangle.Y + 1, control.ClientRectangle.Width - 2, control.ClientRectangle.Height - 2));
                }
                pen.Dispose();
            }
        }

        public override void InitializeNewComponent(IDictionary defaultValues)
        {
            base.InitializeNewComponent(defaultValues);

            WaterRipples waterRipples = (WaterRipples)this.Component;
            MemberDescriptor member = (MemberDescriptor)TypeDescriptor.GetProperties((object)this.Component)["Value"];
            this.RaiseComponentChanging(member);
            waterRipples.Value = 30;
            this.RaiseComponentChanged(member, (object)null, (object)null);
        }
    }
}
